package com.yxhl.zoume.core.specialcar.fragment;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MyLocationStyle;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.custom.CheckBoxLayout;
import com.yxhl.zoume.core.func.pay.model.CarPaymentEntrance;
import com.yxhl.zoume.core.specialcar.model.CarPaymentInfo;
import com.yxhl.zoume.core.specialcar.model.SpecialCarRideStatus;
import com.yxhl.zoume.core.specialcar.presenter.SpecialCarScheduleMapPresenter;
import com.yxhl.zoume.core.specialcar.activity.SpecialCarScheduleActivity;
import com.yxhl.zoume.core.specialcar.model.DialTelephoneEvent;
import com.yxhl.zoume.core.specialcar.model.SpecialCarOrderDispatchFailureEvent;
import com.yxhl.zoume.core.specialcar.view.SpecialCarScheduleMapView;
import com.yxhl.zoume.core.func.appraisal.model.AppraisalDriverInfo;
import com.yxhl.zoume.core.func.map.ui.fragment.BaseMapFragment;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderEvent;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CommentOnDriverView;
import com.yxhl.zoume.data.http.model.specialcar.SpecialCarOrder;
import com.yxhl.zoume.data.http.model.specialcar.SpecialCarPollingLatLng;
import com.yxhl.zoume.data.http.rest.response.specialcar.SpecialCarPollingResponse;
import com.yxhl.zoume.data.rxbus.RxBus;
import com.yxhl.zoume.di.component.car.DaggerSpecialCarComponent;
import com.yxhl.zoume.di.component.car.SpecialCarComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.di.module.car.SpecialCarModule;
import com.yxhl.zoume.domain.interactor.ZMEventSubscriber;
import com.yxhl.zoume.utils.DeviceUtils;
import com.yxhl.zoume.utils.LOG;
import com.yxhl.zoume.utils.PopupWindowUtils;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.ZMDialog;
import com.yxhl.zoume.utils.permission.PermissionHelper;

import java.util.LinkedList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;
import rx.functions.Action1;

/**
 *
 */
public class SpecialCarScheduleMapFragment extends BaseMapFragment implements SpecialCarScheduleMapView, CommentOnDriverView {

    public static final int PICK_UP_MOVE_DURATION = 600;
    public static final int DRIVER_INFO_MOVE_DURATION = 400;
    /**
     * 第二次地图移动的边距
     */
    public static final int MOVE_PADDING = 20;
    private static final String TAG = "SpecialServiceMapFrag";
    private static final int SECOND_ANIMATE_MOVE_DELAY = 1000;
    private static final float MAP_ZOOM_LEVEL = 13;
    @BindView(R.id.frame_fragment_special_car_schedule_root)
    FrameLayout mRootFrame;

    @BindView(R.id.rl_special_car_service_header_container)
    RelativeLayout mHeaderContainerRl;

    //接驾信息栏
    @BindView(R.id.rl_special_car_service_schedule_hint)
    RelativeLayout mScheduleBarRl;
    @BindView(R.id.tv_special_car_service_schedule_title)
    TextView mScheduleTitleTv;
    @BindView(R.id.iv_special_car_service_schedule_icon)
    ImageView mScheduleIconIv;

    //司机信息栏
    @BindView(R.id.rl_special_car_service_driver_info_container)
    RelativeLayout mDriverInfoRl;
    @BindView(R.id.tv_special_car_service_driver_info_title)
    TextView mDriverInfoTitleTv;
    @BindView(R.id.cbl_special_car_service_driver_info_comment)
    CheckBoxLayout mCommentCheckBoxLayout;
    @BindView(R.id.iv_special_car_service_driver_info_phone)
    ImageView mDriverInfoPhoneIv;

    @BindView(R.id.frame_special_car_service_location)
    LinearLayout mLocationFrame;


    //arguments
    @Inject
    SpecialCarScheduleMapPresenter mSpecialCarScheduleMapPresenter;


    private String mSpecialCarOrderId;

    private PopupWindow mPhonePopupWindow;

    private String mDriverMobile;
    /**
     * 出发点经纬度
     */
    private List<SpecialCarPollingLatLng> mDepartLatLngList;

    /**
     * 目的地经纬度
     */
    private List<SpecialCarPollingLatLng> mArrivalLatLngList;

    /**
     * 等待接驾 小车图标帧动画
     */
    private AnimationDrawable mAnimationDrawable;
    private SpecialCarComponent specialCarComponent;


    public SpecialCarScheduleMapFragment() {
        // Required empty public constructor
    }

    public static SpecialCarScheduleMapFragment newInstance(String specialCarOrderId) {

        SpecialCarScheduleMapFragment fragment = new SpecialCarScheduleMapFragment();
        Bundle args = new Bundle();
        args.putString(UIConstants.Car.ARGUMENT_KEY_SPECIAL_CAR_SERVICE_MAP, specialCarOrderId);
        fragment.setArguments(args);
        return fragment;
    }

    public PopupWindow getPhonePopupWindow() {
        return mPhonePopupWindow;
    }

    private void parseArguments() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mSpecialCarOrderId = arguments.getString(UIConstants.Car.ARGUMENT_KEY_SPECIAL_CAR_SERVICE_MAP, "");
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        parseArguments();
        onRxBusEvent();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        mSpecialCarScheduleMapPresenter.attachView(this);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBaseStartMoveToLocation = true;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mSpecialCarScheduleMapPresenter.startPolling(mSpecialCarOrderId);
    }


    @OnClick(R.id.frame_special_car_service_location)
    public void onLocationIconClick(View view) {
        Location location = mMapView.getMap().getMyLocation();
        if (location != null) {
            animateMoveTo(new LatLng(location.getLatitude(), location.getLongitude()), MAP_ZOOM_LEVEL);
        }
    }

    @OnClick(R.id.iv_special_car_service_driver_info_phone)
    public void onDriverInfoPhoneIconClick(View view) {
        showPhonePopupWindow();
    }

    private void showPhonePopupWindow() {
        if (mPhonePopupWindow != null) {
            setWindowBackgroundAlpha(0.5f);
            mPhonePopupWindow.showAtLocation(mRootFrame, Gravity.BOTTOM, 0, 0);
        }
    }

    /**
     * 设置窗口透明度
     *
     * @param bgAlpha
     */
    private void setWindowBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams attributes = mActivity.getWindow().getAttributes();
        attributes.alpha = bgAlpha;
        mActivity.getWindow().setAttributes(attributes);
    }

    /**
     * 关闭电话弹窗
     */
    public void closePhonePopupWindow() {
        if (mPhonePopupWindow != null) {
            if (mPhonePopupWindow.isShowing()) {
                mPhonePopupWindow.dismiss();
            }
        }
    }

    private void initializePhonePopupWindow(SpecialCarOrder order) {

        View contentView = getActivity().getLayoutInflater().inflate(R.layout.popup_special_car_schedule_phone, null);
        TextView mPopupTitleTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_title);
        TextView mPopupContentTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_content);
        TextView mPopupCancelTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_cancel);
        TextView mPopupDialTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_dial);

        if (order != null) {
            mDriverMobile = order.getDriverMobile();
            if (!TextUtils.isEmpty(mDriverMobile)) {
                mPopupTitleTv.setText(mDriverMobile);
            }
        }

        mPopupContentTv.setText(getString(R.string.special_car_popup_dial_content));
        mPopupCancelTv.setText(getString(R.string.special_car_dialog_cancel));
        mPopupDialTv.setText(getString(R.string.special_car_popup_dial_confirm));
        mPopupDialTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (PermissionHelper.checkPhonePermission(mActivity)) {
                    DeviceUtils.dialTelPhone(mActivity, mDriverMobile);
                } else {
                    PermissionHelper.takeCallPhonePermission(mActivity, PermissionHelper.REQUEST_CODE_CALL_SPECIAL_CAR_DRIVER);
                }
            }
        });
        mPopupCancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closePhonePopupWindow();
            }
        });

        mPhonePopupWindow = PopupWindowUtils.getSchedulePhonePopupWindow(contentView);
        mPhonePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setWindowBackgroundAlpha(1f);
            }
        });
    }

    public void onRxBusEvent() {
        getSubscription().add(toSubscription(DialTelephoneEvent.class,
                new Action1<DialTelephoneEvent>() {
                    @Override
                    public void call(DialTelephoneEvent dialTelephoneEvent) {
                        if (dialTelephoneEvent.getFromDirection() == DialTelephoneEvent.FROM_SCHEDULE_DRIVER_MOBILE) {
                            if (!TextUtils.isEmpty(mDriverMobile)) {
                                DeviceUtils.dialTelPhone(mActivity, mDriverMobile);
                            }
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                    }
                }
        ));
        getSubscription().add(toSubscription(CancelTripOrderEvent.class, new Action1<CancelTripOrderEvent>() {
            @Override
            public void call(CancelTripOrderEvent event) {
                ((SpecialCarScheduleActivity)specialCarComponent.context()).finish();
            }
        }));
    }


    /**
     * 司机信息栏进入动画
     */
    private void startEnterAnimatorForDriverInfo(final boolean isRunPickUpEnterAnimator) {
        int height = mDriverInfoRl.getHeight();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mHeaderContainerRl, "translationY", 0, height);
        translateAnimator.setInterpolator(new DecelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mDriverInfoRl, "alpha", 0, 1f);

        AnimatorSet enterAnimatorSet = new AnimatorSet();
        enterAnimatorSet.setDuration(DRIVER_INFO_MOVE_DURATION);
        enterAnimatorSet.playTogether(translateAnimator, alphaAnimator);
        enterAnimatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                if (isRunPickUpEnterAnimator) {
                    startEnterAnimatorForScheduleBar();
                }
            }
        });

        enterAnimatorSet.start();
    }


    /**
     * 获取 动画移动所需的距离
     *
     * @return
     */
    private int getDeltaTranslationX() {
        int screenWidth = DeviceUtils.getScreenWidth(mActivity);
        int pickUpRlWidth = mScheduleBarRl.getWidth();
        return (screenWidth - pickUpRlWidth) / 2 + pickUpRlWidth;
    }


    @Override
    protected Marker getLocationMarker(AMap aMap, LatLng latLng) {

        return null;
    }

    @Override
    protected boolean setUpLocationStyle(AMap aMap) {
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.icon_user_location));
        myLocationStyle.radiusFillColor(Color.TRANSPARENT);
        myLocationStyle.strokeColor(Color.TRANSPARENT);
        aMap.setMyLocationStyle(myLocationStyle);

        return true;
    }

    @Override
    protected float getLocationMapZoomLevel() {
        return MAP_ZOOM_LEVEL;
    }

    @Override
    protected void secondAnimateMove() {
        final List<LatLng> latLngList = new LinkedList<>();
        if (mDepartLatLngList != null && mDepartLatLngList.size() > 0) {
            for (SpecialCarPollingLatLng latLng : mDepartLatLngList) {
                latLngList.add(new LatLng(latLng.getLat(), latLng.getLng()));
            }
        }
        if (mArrivalLatLngList != null && mArrivalLatLngList.size() > 0) {
            for (SpecialCarPollingLatLng latLng : mArrivalLatLngList) {
                latLngList.add(new LatLng(latLng.getLat(), latLng.getLng()));
            }
        }

        mRootFrame.postDelayed(new Runnable() {
            @Override
            public void run() {
                animateMoveTo(latLngList, MOVE_PADDING);
            }
        }, SECOND_ANIMATE_MOVE_DELAY);
    }


    @Override
    public void renderDataOnFailure(String resultMessage) {
        PromptUtils.showShort(getContext(), resultMessage);
    }

    @Override
    public void renderDataOnSuccess(SpecialCarPollingResponse response) {
        mDepartLatLngList = response.getLnglats();
        mArrivalLatLngList = response.getElnglats();
        mSpecialCarScheduleMapPresenter.refreshMarkersInMap(
                mMapView.getMap(),
                mDepartLatLngList,
                mArrivalLatLngList
        );
    }

    /**
     * 订单信息栏进入动画
     */
    @Override
    public void startEnterAnimatorForScheduleBar() {
        //开启小车帧动画
        mAnimationDrawable = (AnimationDrawable) mScheduleIconIv.getDrawable();
        mAnimationDrawable.start();

        int deltaTranslationX = getDeltaTranslationX();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "translationX", 0, deltaTranslationX);
        translateAnimator.setInterpolator(new DecelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "alpha", 0.3f, 1);
        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "scaleX", 0.3f, 1);

        AnimatorSet enterAnimatorSet = new AnimatorSet();
        enterAnimatorSet.setDuration(PICK_UP_MOVE_DURATION);
        enterAnimatorSet.playTogether(translateAnimator, alphaAnimator, scaleXAnimator);

        enterAnimatorSet.start();
    }

    /**
     * 司机信息栏退出动画
     */
    @Override
    public void startExitAnimatorForDriverInfo() {
        int height = mDriverInfoRl.getHeight();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mHeaderContainerRl, "translationY", height, 0);
        translateAnimator.setInterpolator(new AccelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mDriverInfoRl, "alpha", 1f, 0.6f);

        AnimatorSet exitAnimatorSet = new AnimatorSet();
        exitAnimatorSet.setDuration(DRIVER_INFO_MOVE_DURATION);
        exitAnimatorSet.playTogether(translateAnimator, alphaAnimator);

        exitAnimatorSet.start();
    }

    @Override
    public void setupHeaderStatus(String title, String operation) {
        if (mActivity instanceof SpecialCarScheduleActivity) {
            SpecialCarScheduleActivity scheduleActivity = (SpecialCarScheduleActivity) mActivity;
            scheduleActivity.setToolbar(title, operation);
        }
    }

    @Override
    public void setupScheduleBarStatus(String message, boolean iconVisibility) {
        if (iconVisibility) {
            mScheduleIconIv.setVisibility(View.VISIBLE);
        } else {
            mScheduleIconIv.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(message)) {
            mScheduleTitleTv.setText(message);
        }
    }

    /**
     * @param driverInfo 司机姓名和车牌号
     * @param judgePoint
     */
    @Override
    public void setupDriverInfoStatus(String driverInfo, double judgePoint, boolean isPhoneIconVisible) {
        if (!TextUtils.isEmpty(driverInfo)) {
            mDriverInfoTitleTv.setVisibility(View.VISIBLE);
            if (isPhoneIconVisible) {
                mDriverInfoPhoneIv.setVisibility(View.VISIBLE);
            } else {
                mDriverInfoPhoneIv.setVisibility(View.INVISIBLE);
            }

            mDriverInfoTitleTv.setText(driverInfo);
            mCommentCheckBoxLayout.setCheckedCount(judgePoint);
        } else {
            mDriverInfoTitleTv.setVisibility(View.INVISIBLE);
            mDriverInfoPhoneIv.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    public void showTimeOutDialog() {
        ZMDialog zmDialog = new ZMDialog.Builder(mActivity)
                .setMessage(getString(R.string.special_car_dialog_time_out_message))
                .setPositiveMessage(getString(R.string.special_car_dialog_confirm))
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        getActivity().finish();
                    }
                })
                .show();
    }

    @Override
    public void showSDispatchFailureDialog() {
        ZMDialog zmDialog = new ZMDialog.Builder(mActivity)
                .setTitle(getString(R.string.special_car_dialog_dispatch_failure_title))
                .setMessage(getString(R.string.special_car_dialog_dispatch_failure_message))
                .setPositiveMessage(getString(R.string.special_car_dialog_dispatch_failure_positive))
                .setNegativeMessage(getString(R.string.special_car_dialog_dispatch_failure_negative))
                .setPositiveClickEvent(new ZMEventSubscriber())
                .setNegativeClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        getActivity().finish();
                        RxBus.getInstance().send(new SpecialCarOrderDispatchFailureEvent());
                    }
                })
                .show();
    }

    @Override
    public void showInvalidDataDialog() {
        ZMDialog zmDialog = new ZMDialog.Builder(mActivity)
                .setMessage(getString(R.string.special_car_dialog_invalidate_order))
                .setPositiveMessage(getString(R.string.special_car_dialog_confirm))
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        getActivity().finish();
                    }
                })
                .show();
    }

    @Override
    public void showDriverCloseDialog() {
        ZMDialog zmDialog = new ZMDialog.Builder(mActivity)
                .setMessage(getString(R.string.special_car_dialog_driver_close_order_message))
                .setPositiveMessage(getString(R.string.special_car_dialog_confirm))
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        getActivity().finish();
                    }
                })
                .show();
    }


    /**
     * 订单信息栏退出动画
     *
     * @param
     */
    @Override
    public void startExitAnimatorForScheduleBar() {
        //关闭小车帧动画
        if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
            mAnimationDrawable.stop();
        }

        int deltaTranslationX = getDeltaTranslationX();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "translationX", deltaTranslationX, 0);
        translateAnimator.setInterpolator(new AccelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "alpha", 1, 0.3f);
        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "scaleX", 1, 0.3f);

        AnimatorSet exitAnimatorSet = new AnimatorSet();
        exitAnimatorSet.setDuration(PICK_UP_MOVE_DURATION);
        exitAnimatorSet.playTogether(translateAnimator, alphaAnimator, scaleXAnimator);

        exitAnimatorSet.start();
    }

    @Override
    public void updateDataBetweenRideStatus(int fromRideStatus, int toRideStatus, SpecialCarOrder order) {
        if (fromRideStatus == SpecialCarRideStatus.DISPATCH
                && toRideStatus == SpecialCarRideStatus.UN_GET_IN) {
            setupScheduleBarStatus(getString(R.string.depart_customer_hint), false);
            initializePhonePopupWindow(order);
        } else if (fromRideStatus == SpecialCarRideStatus.UN_GET_IN
                && toRideStatus == SpecialCarRideStatus.DISPATCH) {
            setupScheduleBarStatus(getString(R.string.depart_wait_hint_again), true);
        }
    }

    @Override
    public void startEnterAnimatorForDriverInfoAndScheduleBar(boolean runNextAnimator) {
        startEnterAnimatorForDriverInfo(runNextAnimator);
    }

    @Override
    public void ShowArrivalDialog(final SpecialCarOrder order) {
        //评论页



        ZMDialog dialog = new ZMDialog.Builder(specialCarComponent.context())
                .setTitle("行程结束")
                .setMessage("您本次行程花费" + order.getTotalFee() + "元")
                .setPositiveMessage("去评价")
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        AppraisalDriverInfo driverInfo = new AppraisalDriverInfo();
                        driverInfo.setOrderId(mSpecialCarOrderId)
                                .setDriverName(order.getDriverName())
                                .setPlateNumber(order.getVehicleNo())
                                .setHistoryScore(mCommentCheckBoxLayout.getBoxCount());

                        getAppComponent().navigator().navigateToAppraisal((SpecialCarScheduleActivity) specialCarComponent.context(), driverInfo);
                        ((SpecialCarScheduleActivity) specialCarComponent.context()).finish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }).show();
    }

    @Override
    public void showPaymentDialog(final SpecialCarOrder order) {
        ZMDialog dialog = new ZMDialog.Builder(specialCarComponent.context())
                .setTitle("行程结束")
                .setMessage("您本次行程花费" + order.getTotalFee() + "元")
                .setPositiveMessage("去支付")
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        CarPaymentInfo paymentInfo = new CarPaymentInfo();
                        paymentInfo
                                .setCarPaymentEntrance(CarPaymentEntrance.getCarPaymentEntranceByBizType(Integer.parseInt(order.getBizType())))
                                .setOrderId(order.getId())
                                .setBizType(Integer.parseInt(order.getBizType()))
                                .setTotalFee(order.getTotalFee())
                                .setDriverName(order.getDriverName())
                                .setPlateNumber(order.getVehicleNo())
                                .setHistoryScore(mCommentCheckBoxLayout.getBoxCount());
                        getAppComponent().navigator().navigateToSpecialCarPayment((SpecialCarScheduleActivity) specialCarComponent.context(), paymentInfo);
                        ((SpecialCarScheduleActivity) specialCarComponent.context()).finish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }).show();
    }

    @Override
    public void closeCommentOnCompleted() {
    }

    @Override
    public void renderCommentOnError(String msg) {
    }

    @Override
    public void renderCommentOnSuccess() {
    }

    @Override
    public void onDestroyView() {
        closePhonePopupWindow();
        if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
            mAnimationDrawable.stop();
        }
        mSpecialCarScheduleMapPresenter.onDestroy();
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        getSubscription().unsubscribe();
        super.onDestroy();
    }


    @Override
    protected void initializeInjector() {
        specialCarComponent = DaggerSpecialCarComponent.builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(mActivity))
                .specialCarModule(new SpecialCarModule())
                .build();
        specialCarComponent.inject(this);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_special_car_schedule;
    }

    @Override
    protected void setupToolBar() {
        if (mActivity instanceof SpecialCarScheduleActivity) {
            SpecialCarScheduleActivity scheduleActivity = (SpecialCarScheduleActivity) mActivity;
            scheduleActivity.setToolbar(
                    getString(R.string.route_detail_no_charter),
                    getString(R.string.special_car_operation_cancel_trip));
        }
    }
}
